package com.example.cookieshop.common;


import com.example.cookieshop.entity.User;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;

/**
 * 用户登录的相关操作
 */
public class UserSessionUtils {

    public static User getSessionUser(HttpServletRequest request) {
        // 1.获取当前的用户(从session中获取)
        HttpSession session = request.getSession(false);
        if (session == null) {
            return null;
        }
        User user = (User) session.getAttribute(GlobalVariable.USER_SESSION_KEY);
        return user;
    }
}
